package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.app.AlertDialog;
import android.app.ExpandableListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class ConferenceExpandableListActivity extends ExpandableListActivity {

	private ConferenceExpandableListAdapter mAdapter;


	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);

		try {
			mAdapter = new ConferenceExpandableListAdapter(this, getString(R.string.getConferences));
		} catch (ConnectException e) {
			Toast.makeText(this, "unable to Connect to Server", Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
		setListAdapter(mAdapter);

	}

	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(Menu.NONE, Menu.FIRST, Menu.NONE, "About Us").setIcon(android.R.drawable.ic_menu_help);
		//menu.add(Menu.NONE, Menu.FIRST+1, Menu.NONE, "Settings").setIcon(android.R.drawable.ic_menu_edit);
		return true;
	}

	public void DisplayAbout(){

		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage(getString(R.string.about))
		.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
			}
		}).setTitle("SHPE Version 1.0").show();

		//AlertDialog alert = builder.create();

		return;
	}
	
	/* Handles item selections */
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case Menu.FIRST:	
			DisplayAbout();
			break;

			// Display Preference Activity
			/*
		case Menu.FIRST+1:
			Intent intent = new Intent();
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.setClass(getBaseContext(), PrefActivity.class);
			startActivity(intent);
			break;
	       */

		default:
			return false;
		}
		return true;
	}
	
	
	public void onClick(View view){
		
		Log.i("ListActivity", "btnpress id =" + view.getId());
		
		Intent intent = new Intent(this, ConferenceDisplayActivity.class);
		intent.putExtra("id", view.getId());
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		
		startActivity(intent);
	}

}